package com.jf.listener;

import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-09-01
 * Time:23:58
 */
@WebListener
public class JFServletRequestListener implements ServletRequestListener {
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        System.out.println("===================================================================================");
        System.out.println("JF detected that request was destroyed");
        System.out.println("===================================================================================");
    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        System.out.println("===================================================================================");
        System.out.println("JF listens to request being created");
        ServletRequest request = servletRequestEvent.getServletRequest();
        System.out.println("Access log");
        System.out.println("Access IP: " + request.getRemoteAddr());
        System.out.println("Access resource: " + ((HttpServletRequest)request).getRequestURL());
        System.out.println("===================================================================================");
    }
}
